package com.example.springbolgdemo.controller;

import com.example.springbolgdemo.pojo.request.AddBlogRequest;
import com.example.springbolgdemo.pojo.request.UpdateBlogRequest;
import com.example.springbolgdemo.pojo.response.BlogDetailResponse;
import com.example.springbolgdemo.pojo.response.BlogInfoResponse;
import com.example.springbolgdemo.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RequestMapping("blog")
@RestController
public class BlogInfoController {

    @Resource(name = "blogService")
    BlogService blogService;

    @RequestMapping("/getList")
    public List<BlogInfoResponse> getList(){
        log.info("获取博客列表...");
        return blogService.getList();
    }

    @RequestMapping("/getBlogDetail")
    public BlogDetailResponse getBlogDetail(@NotNull(message = "blogId不能为空") Integer blogId){
        log.info("获取博客详情...,blogId:{}",blogId);
        return blogService.getBlogDetail(blogId);
    }

    @RequestMapping("/add")
    public Boolean addBlog(@RequestBody @Validated AddBlogRequest addBlogRequest){
        log.info("添加博客,addBlogRequest: ",addBlogRequest);
        return blogService.addBlog(addBlogRequest);
    }

    @RequestMapping("/update")
    public Boolean updateBlog(@Validated @RequestBody UpdateBlogRequest updateBlogRequest){
        log.info("更新博客,updateBlogRequest",updateBlogRequest);
        return blogService.updateBlog(updateBlogRequest);
    }

    @RequestMapping("/delete")
    public Boolean deleteBlog(@NotNull(message = "blogId不能为空") Integer blogId){
        log.info("删除博客,blogId",blogId);
        return blogService.deleteBlog(blogId);
    }

}
